function renderState(config, state) {
	// Draw background
	fillRect(0, 0, 800, 600)

	// Draw room
	switch (state.at) {
		// Room 1
		case 1:
			// Draw background behind the door
			if (state.leftDoorLight) {
				fillRect(250, 200, 200, 300, { fill: '#048' })

				// Draw antagonist
				if (state.antagonistIota == 3) {
					// Draw Iota
					drawImage('assets/character/iota.png', 200, 240, 300, 300)
				}
				if (state.antagonistOmicron == 3) {
					// Draw Omicron
					drawImage('assets/character/omicron.png', 200, 240, 300, 300)
				}
				if (state.antagonistAlpha == 3) {
					// Draw Alpha
					drawImage('assets/character/alpha.png', 200, 240, 300, 300)
				}
				if (state.antagonistOmega == 3) {
					// Draw Omega
					drawImage('assets/character/omega.png', 200, 240, 300, 300)
				}
			} else
				fillRect(250, 200, 200, 300, { fill: '#000' })

			// Draw door
			let doorHeight = 300 * state.leftDoorPosition
			fillRect(250, 200, 200, doorHeight, { fill: '#444' })
			strokeRect(250, 200, 200, doorHeight, { lineWidth: 10 })

			// Render room
			renderRoom1()

			// Draw light button
			let lightClicked = uiRectButton(480, 350, 25, 25, { fillHover: '#444', fillClick: '#666' })
			if (lightClicked) {
				if (!state.leftDoorLightClicked) {
					state.leftDoorLightClicked = true
					if (state.leftDoorLight)
						state.leftDoorLight = false
					else {
						state.leftDoorLight = true
						if (!state.leftDoorClosed && (state.antagonistIota == 3 || state.antagonistOmicron == 3 || state.antagonistAlpha == 3 || state.antagonistOmega == 3))
							playAudio('assets/sound/windowscare.ogg')
					}
				}
			} else
				state.leftDoorLightClicked = false

			// Draw close button
			let closedClicked = uiRectButton(480, 300, 25, 25, { fillHover: '#444', fillClick: '#666' })
			if (closedClicked) {
				if (!state.leftDoorClosedClicked) {
					state.leftDoorClosedClicked = true
					playAudio('assets/sound/door.ogg')
					if (state.leftDoorClosed)
						state.leftDoorClosed = false
					else
						state.leftDoorClosed = true
				}
			} else
				state.leftDoorClosedClicked = false

			// Draw desk and monitor
			renderRoom1DeskAndMonitor()

			// Switch to room 2
			if (!state.cameraOn) {
				if (uiRectButton(700, 0, 100, 600, { stroke: '#FFFFFF00', fill: '#FFFFFF00', fillHover: '#FFFFFF00', fillClick: '#FFFFFF00' }))
					state.at = 2
				fillText('>>', 770, 300, { fontSize: 50 })
			}

			break

		// Room 2
		case 2:
			// Draw background behind the door
			if (state.rightDoorLight) {
				fillRect(350, 200, 200, 300, { fill: '#048' })

				// Draw antagonist
				if (state.antagonistIota == 4) {
					// Draw Iota
					drawImage('assets/character/iota.png', 300, 240, 300, 300)
				}
				if (state.antagonistOmicron == 4) {
					// Draw Omicron
					drawImage('assets/character/omicron.png', 300, 240, 300, 300)
				}
				if (state.antagonistAlpha == 4) {
					// Draw Alpha
					drawImage('assets/character/alpha.png', 300, 240, 300, 300)
				}
				if (state.antagonistOmega == 4) {
					// Draw Omega
					drawImage('assets/character/omega.png', 300, 240, 300, 300)
				}
			} else
				fillRect(350, 200, 200, 300, { fill: '#000' })

			// Draw door
			let doorHeight2 = 300 * state.rightDoorPosition
			fillRect(350, 200, 200, doorHeight2, { fill: '#444' })
			strokeRect(350, 200, 200, doorHeight2, { lineWidth: 10 })

			// Render room
			renderRoom2()

			// Draw light button
			let lightClicked2 = uiRectButton(295, 350, 25, 25, { fillHover: '#444', fillClick: '#666' })
			if (lightClicked2) {
				if (!state.rightDoorLightClicked) {
					state.rightDoorLightClicked = true
					if (state.rightDoorLight)
						state.rightDoorLight = false
					else {
						state.rightDoorLight = true
						if (!state.rightDoorClosed && (state.antagonistIota == 4 || state.antagonistOmicron == 4 || state.antagonistAlpha == 4 || state.antagonistOmega == 4))
							playAudio('assets/sound/windowscare.ogg')
					}
				}
			} else
				state.rightDoorLightClicked = false

			// Draw close button
			let closedClicked2 = uiRectButton(295, 300, 25, 25, { fillHover: '#444', fillClick: '#666' })
			if (closedClicked2) {
				if (!state.rightDoorClosedClicked) {
					state.rightDoorClosedClicked = true
					playAudio('assets/sound/door.ogg')
					if (state.rightDoorClosed)
						state.rightDoorClosed = false
					else
						state.rightDoorClosed = true
				}
			} else
				state.rightDoorClosedClicked = false

			// Draw desk and monitor
			renderRoom2DeskAndMonitor()

			// Switch to room 1
			if (!state.cameraOn) {
				if (uiRectButton(0, 0, 100, 600, { stroke: '#FFFFFF00', fill: '#FFFFFF00', fillHover: '#FFFFFF00', fillClick: '#FFFFFF00' }))
					state.at = 1
				fillText('<<', 30, 300, { fontSize: 50 })
			}

			break
	}

	// Draw monitor system
	if (state.cameraOn) {
		// Draw monitor
		fillRect(100, 75, 600, 450)

		// Draw monitor image
		switch (state.cameraAt) {
			// Room 5
			case 5:
				// Draw room
				renderRoom5()
				break

			// Room 6
			case 6:
				// Draw room
				renderRoom6()
				break

			// Room 7
			case 7:
				// Draw room
				renderRoom7()
				break

			// Room 8
			case 8:
				// Draw room
				renderRoom8()
				break

			// Room 9
			case 9:
				// Camera unavailable
				drawGlitch(100, 75, 600, 450, { glitch: 100 })
				break

			// Room 10
			case 10:
				// Draw room
				renderRoom10()
				break

			// Room 11
			case 11:
				// Draw room
				renderRoom11()
				break

			// Room 12
			case 12:
				// Draw room
				renderRoom12()
				break

			// Room 13
			case 13:
				// Draw room
				renderRoom13()
				break
		}

		// Draw antagonist
		if (state.antagonistIota == state.cameraAt) {
			// Draw Iota
			drawImage('assets/character/iota.png', 100, 240, 300, 300)
		}
		if (state.antagonistOmicron == state.cameraAt) {
			// Draw Omicron
			drawImage('assets/character/omicron.png', 200, 240, 300, 300)
		}
		if (state.antagonistAlpha == state.cameraAt) {
			// Draw Alpha
			drawImage('assets/character/alpha.png', 300, 240, 300, 300)
		}
		if (state.antagonistOmega == state.cameraAt) {
			// Draw Omega
			switch (state.antagonistOmega) {
				case 5:
					drawImage('assets/character/glitch/omega' + (state.antagonistOmegaStage + 1).toString() + '.png', 0, 240, 300, 300)
					break
				case 6:
					drawImage('assets/character/glitch/omega0.png', 500 * state.antagonistOmegaMovement, 240 + 50 * Math.sin(state.antagonistOmegaMovement * 50), 300, 300)
					break
			}
		}
		if (state.antagonistAlpha == state.cameraAt && state.antagonistAlpha != 12) {
			// Draw Alpha glitch
			drawGlitch(100, 75, 600, 450, { glitch: 100 })
		}

		// Draw monitor glitch
		drawGlitch(100, 75, 600, 450, { glitch: state.cameraGlitch })

		// Draw minimap
		function drawCameraMinimap(x, y, width, height, at, text) {
			if (state.cameraAt == at) {
				fillRect(x, y, width, height, { fill: '#008' })
				strokeRect(x, y, width, height)
			} else {
				if (uiRectButton(x, y, width, height, { fillHover: '#444', fillClick: '#666' }))
					state.cameraAt = at
			}
			fillText(text, x + width * .5, y + height * .5 + 1)
		}
		drawCameraMinimap(480, 400, 40, 40, 5, '4')
		drawCameraMinimap(520, 400, 40, 40, 6, '3A')
		drawCameraMinimap(560, 400, 40, 40, 7, '3B')
		drawCameraMinimap(600, 400, 40, 40, 8, '3C')
		drawCameraMinimap(640, 400, 40, 40, 9, '5')
		drawCameraMinimap(560, 380, 40, 20, 10, '2B')
		drawCameraMinimap(520, 340, 40, 60, 11, '2A')
		drawCameraMinimap(560, 340, 40, 40, 12, '1')
		drawCameraMinimap(600, 340, 40, 60, 13, '2C')
		fillRect(500, 440, 160, 20)
		strokeRect(500, 440, 160, 20)
		fillRect(540, 460, 80, 40)
		strokeRect(540, 460, 80, 40)
		fillText('YOU', 580, 480)

		// Draw monitor edge
		strokeRect(100, 75, 600, 450, { lineWidth: 10 })

		// Draw info
		fillText(getTimeText(state.time), 175, 460, { fill: '#888' })
		fillText('POWER:', 200, 480, { alignX: 'right', fill: '#888' })
		fillText(Math.ceil(state.power).toFixed(0) + '%', 205, 480, { alignX: 'left', fill: '#888' })
		let usage = calculatePowerUsage(config, state)
		fillText('USAGE:', 200, 500, { alignX: 'right', fill: '#888' })
		for (let i = 0; i < usage; ++i)
			fillRect(205 + 18 * i, 490, 15, 20, { fill: (i < 2) ? '#0F0' : ((i < 4) ? '#FF0' : '#F00') })
	}

	// Draw monitor button
	if (!state.powerOutage) {
		let cameraButtonClicked = uiRectButton(100, 540, 600, 50, { fillHover: '#444', fillClick: '#666', hoverClick: true })
		if (cameraButtonClicked) {
			if (!state.cameraButtonClicked) {
				state.cameraButtonClicked = true
				if (state.cameraOn) {
					state.cameraOn = false
					playAudio('assets/sound/cameraOff.ogg')
				} else {
					state.cameraOn = true
					playAudio('assets/sound/cameraOn.ogg')
				}
			}
		} else
			state.cameraButtonClicked = false
		fillText('CAMERA SYSTEM', 400, 566)
	}

	// Draw power outage
	if (state.powerOutage)
		fillRect(0, 0, 800, 600, { fill: '#00000080' })

	// Draw jumpscare
	if (state.jumpscared) {
		switch (state.jumpscaredBy) {
			case 'iota':
				drawImage('assets/character/glitch/iota1.png', 100 * Math.sin(50 * state.jumpscaredTime), 50 * Math.sin(35 * state.jumpscaredTime) - 100, 800, 800)
				break
			case 'omicron':
				drawImage('assets/character/glitch/omicron1.png', 100 * Math.sin(50 * state.jumpscaredTime), 50 * Math.sin(35 * state.jumpscaredTime) - 100, 800, 800)
				break
			case 'alpha':
				drawImage('assets/character/glitch/alpha1.png', 100 * Math.sin(50 * state.jumpscaredTime), 50 * Math.sin(35 * state.jumpscaredTime) - 100, 800, 800)
				break
			case 'omega':
				drawImage('assets/character/glitch/omega0.png', 100 * Math.sin(50 * state.jumpscaredTime), 50 * Math.sin(35 * state.jumpscaredTime) - 100, 800, 800)
				break
		}
	}
}